import React from 'react';
import _ from 'lodash';
import { Input, Select } from 'antd';
import CommonTable from '@/components/CommonTable';
import { fetchListByDesignProTable } from '@/services/online/onlinePage';

const searchComponent = { Input, Select };

export const RealProTable = (props) => {
  const { search, requestConfig, ...restProps } = props;
  const { url } = requestConfig || {};

  return (
    <CommonTable
      {...restProps}
      search={_.map(search || [], ({ Component, ...restOpts }) => ({
        ...restOpts,
        Component: searchComponent[Component],
      }))}
      request={async (params) => {
        const { records, total } = await fetchListByDesignProTable(url || '', params);
        return { data: records, count: total };
      }}
    />
  );
};
